package ms.jacrim.tropos;

import org.w3c.dom.Element;

public class Ownership extends Relationship {
	private static final String OWNERSHIP_TEMPLATE = "<object xmi:type=\"%s\" xmi:id=\"%s\""
			+ " source=\"%s\" target=\"%s\" ownershipType=\"%s\" instantiation=\"%s\" />\r\n";

	// public static final String REQUEST = "REQUEST";
	// public static final String OWN = "OWN";
	// public static final String PROVIDE = "PROVIDE";

	public enum Type {
		REQUEST, OWN, PROVIDE
	};

	private Type ownershipType;
	private String instantiation;

	public Ownership(Diagram diagram, TroposObject source, TroposObject target) {
		super(diagram, source, target);
		setType(TroposObject.OWNERSHIP);
	}

	public Ownership(Diagram diagram, Element element) {
		super(diagram, element);
	}

	void populate(Element element) {
		super.populate(element);

		this.ownershipType = Type.valueOf(element.getAttribute("ownershipType"));
		this.instantiation = element.getAttribute("instantiation");
	}

	public Type getOwnershipType() {
		return ownershipType;
	}

	public void setOwnershipType(Type ownershipType) {
		this.ownershipType = ownershipType;
	}

	public String getInstantiation() {
		return instantiation;
	}

	public void setInstantiation(String instantiation) {
		this.instantiation = instantiation;
	}

	void toString(StringBuilder result, int part, int indent) {
		super.toString(result, part, indent);
		if (part == 0) {
			writeIndent(result, indent);
			result.append(String.format(OWNERSHIP_TEMPLATE, this.getType(), this.getId(), this.getSourceId(), this.getTargetId(), this
					.getOwnershipType(), this.getInstantiation()));
		}
	}

	@Override
	protected int NotationEdgeType() {
		// TODO Auto-generated method stub
		return 0;
	}
}
